<!DOCTYPE html>
<html lang="en">

<head>
    <title>外观模式</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
    <script>
        var A = {
            //通过ID获取元素
            g: function (id) {
                return document.getElementById(id);
            },
            //设置元素css属性
            css: function (id, key, value) {
                document.getElementById(id).style[key] = value;
            },
            //设置元素的属性
            attr: function (id, key, value) {
                document.getElementById(id)[key] = value;
            },
            html: function (id, html) {
                document.getElementById(id).innerHTML = html;
            },
            addEvent: function (id, type, fn) {
                //对于支持DOM2级事件处理程序addEventListener方法的浏览器
                var dom = document.getElementById(id);
                if (dom.addEventListener) {
                    dom.addEventListener(type, fn.false);
                } else if (dom.attachEvent) {
                    dom.attachEvent('on' + type, fn);
                } else {
                    dom['on' + type] = fn;
                }
            },
            //为元素绑定事件
            on: function (id, type, fn) {
                this.addEvent(id, type, fn);
            }
        };
        //参数适配器
        function dosomething(obj) {
            var _adapter = {
                name: "雨夜清荷",
                title: '设计模式',
                age: 24,
                color: 'pink',
                size: 100,
                prize: 50
            };
            for (var i in _adapter) {
                _adapter[i] = obj[i] || _adapter;
            }
            //dothing
        }
        //数据适配
        function attrToObjAdapter(arr) {
            return {
                name: attr[0],
                type: arr[1],
                title: attr[2],
                data: attr[3]
            }
        }
        //服务端数据适配
        function ajaxAdapter(data) {
            return [
                data['key1'],
                data['key2'],
                data['key3']
            ];
        }
        $.ajax({
            url: "url",
            success: function (data) {
                if (data) {
                    dosomething(ajaxAdapter(data));
                }
            }
        });
    </script>
</body>

</html>